<?php include("session.inc.php"); ?>
<?php require_once("../common/config.inc.php");?>
<?php include("../common/db.inc.php"); ?>
<?php
	init();		
	
	function init(){
		$action=$_GET["action"];		
		if($action=="delete"){
			$userid=$_GET["userid"];
			deleteUser($userid);
		}
	}
	
	function deleteUser($userid){
		$sql = "delete FROM medcdb.t_user where userid='$userid'";
		$connection=getMEDCConnection();
		executeUpdate($sql,$connection);		
	}
	
	function getUsers(){
		$sql = "SELECT * FROM medcdb.t_user ORDER BY userid";
		$connection=getMEDCConnection();
		$userArray=executeQuery($sql,$connection);
		return $userArray;
	}
			
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="" />
<meta name="Description" content="" />
<meta name="author" content="" />
<title>User List Page</title>
<link href="../css/medc.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript">	
	function doGet(actionURL,actionName){
		if(actionName=="DeleteUser"){
		    var isConfirm = window.confirm("Are you sure to delete the user?");
		    if (isConfirm == false) {
		        return;
		    }			
		}
		location.href=actionURL;		
	}
</script>
</head>
<body>
	<div id="toparea">
		<?php include "../common/header.inc.php"?>
	</div>	
	
	<div id="menu">
		<?php include "AdminMenu.inc.php";?>
	</div>

	<!--Main area-->
	<div id="mainarea">
		<style>
		.mytable{width:750px;border-spacing:0;margin-left:20px;}
		.mytable th,td {border:1px solid #CCC;}
		.mytable th {background-color:#EEE;}
		</style>
		<form method="get" action="" name="medcform">
			<table class="mytable">
				<thead>
					<tr class="">
						<th>UserID</th>
						<th>Type</th>
						<th>ValFrom</th>
						<th>ValTo</th>
						<th>Contract</th>
						<th>Comment</th>
						<!--<th>Create</th>-->									
						<th>Operation</th>
					</tr>
				</thead>
				<tbody>
				<!--
				<tr>
					<td align="center">test user1</td>
					<td align="center">normal</td>
					<td align="center">2011-03-03</td>	
					<td align="center">2011-03-03</td>	
					<td align="center">hard code Contact info</td>
					<td align="center">hard code comment</td>
					<td align="center">2012-03-03</td>					
					<td align="center">
						<input type="button" id="modify_x" name="modify" value="Modify" onclick=""/>
						<input type="button" id="delete_x" name="delete" value="Delete" onclick=""/>
					</td>
				</tr>
				-->
				<?php
				//$users = array();		
				$users=getUsers();
				//$columnNames=array("userid","usertype","valfrom","valto","contactinfo","comment","createdate");	
				$columnNames=array("userid","usertype","valfrom","valto","contactinfo","comment");
				$i=0;
				foreach ($users as $user){	
				?>
				<tr>	
					<?php foreach ($columnNames as $colName){	?>
				<td align="center"><?php echo $user[$colName]; ?></td>
				<?php
				}
				?>					
					<td align="center" nowrap="true">
						<input type="button" id="modify_<?php echo $i ?>" name="modify" value="Modify" 
							onclick="doGet('UserModify.php?userid=<?php echo $user["userid"]?>&action=modify','ModifyUser')"/>
							<input type="button" id="delete_<?php echo $i ?>" name="delete" value="Delete" 
							onclick="doGet('UserList.php?userid=<?php echo $user["userid"]?>&action=delete','DeleteUser')"/>
						</td>			
					</tr>		
					<?php
					$i++;}
					?>
				</tbody>	
			</table>
		</form>
	</div>
	<div class="myclear"></div>
	<div id="footer">
		<?php include "../common/footer.inc.php";?>
	</div>
</body>
</html>
